package org.example.corpus.common;

public class ResponseResult<T> {

    private Integer code;    // 响应码
    private String message;  // 响应消息
    private T data;          // 响应数据，可以是任意类型

    // 构造函数
    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    // 静态方法用于成功响应
    public static <T> ResponseResult<T> success(T data,String message) {
        return new ResponseResult<>(0, message, data);
    }
    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(0, "操作成功");
    }
    public static <T> ResponseResult<T> success(String message) {
        return new ResponseResult<>(0, message);
    }
    // 静态方法用于错误响应
    public static <T> ResponseResult<T> error(String message) {
        return new ResponseResult<>(1, message, null);
    }

    // Getters 和 Setters
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
